///****************************************
// * Copyright (c) 2015 NiuWa.
// * All rights reserved.
// * Created on 2015年4月15日
// * 
// * Contributors:
// * 	   Percy.Lo - initial implementation
// ****************************************/
//package com.niuwa.p2p.service.impl.exchange;
//
//import static com.niuwa.p2p.server.manggoDB.exchange.ExchangeMongoDBHelper.*;
//
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.LinkedList;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import com.mongodb.BasicDBObject;
//import com.mongodb.DBObject;
//
//import static com.niuwa.p2p.core.constant.Constants.*;
//
//import com.niuwa.p2p.core.enums.GatheringFoundType;
//import com.niuwa.p2p.core.enums.MongoQueueEnum;
//import com.niuwa.p2p.core.utils.CalculateBusiUtils;
//import com.niuwa.p2p.core.utils.DictConstant;
//import com.niuwa.p2p.core.utils.DictConstant.CreditTransStatus;
//import com.niuwa.p2p.core.utils.DictConstant.INVEST_RECORD_STATUS;
//import com.niuwa.p2p.core.utils.DictConstant.InvestMethod;
//import com.niuwa.p2p.core.utils.DictConstant.LoanAuditStatus;
//import com.niuwa.p2p.core.utils.DictConstant.PlanAuditStatus;
//import com.niuwa.p2p.core.utils.DictConstant.ProductIdType;
//import com.niuwa.p2p.core.utils.DictConstant.ReleaseStatus;
//import com.niuwa.p2p.core.utils.DictConstant.TranferStatus;
//import com.niuwa.p2p.dao.business.CustClaimDao;
//import com.niuwa.p2p.dao.business.InvestProdRecordDao;
//import com.niuwa.p2p.dao.business.InvestTransDao;
//import com.niuwa.p2p.dao.business.LoanClaimDao;
//import com.niuwa.p2p.dao.business.ReceivePlanDao;
//import com.niuwa.p2p.dao.claimtransfer.PlanTransferDao;
//import com.niuwa.p2p.dao.claimtransfer.TransProductDao;
//import com.niuwa.p2p.dao.claimtransfer.TransferApplyDao;
//import com.niuwa.p2p.dao.claimtransfer.TransferRecordDao;
//import com.niuwa.p2p.dao.customer.CustomerDao;
//import com.niuwa.p2p.dao.productTemplate.ProductDao;
//import com.niuwa.p2p.entity.business.CustClaim;
//import com.niuwa.p2p.entity.business.InvestProdRecord;
//import com.niuwa.p2p.entity.business.InvestTrans;
//import com.niuwa.p2p.entity.business.LoanClaim;
//import com.niuwa.p2p.entity.claimtransfer.PlanTransfer;
//import com.niuwa.p2p.entity.claimtransfer.TransProduct;
//import com.niuwa.p2p.entity.claimtransfer.TransferApply;
//import com.niuwa.p2p.entity.claimtransfer.TransferRecord;
//import com.niuwa.p2p.entity.customer.Customer;
//import com.niuwa.p2p.entity.productTemplate.Product;
//import com.niuwa.p2p.exception.StaleObjectStateException;
//import com.niuwa.p2p.server.manggoDB.exchange.FundResult;
//import com.niuwa.p2p.service.exchange.IFinishProductService;
//import com.niuwa.p2p.service.exchange.IMatchInnerService;
//import com.niuwa.p2p.service.sequence.ISequenceService;
//import com.niuwa.p2p.utils.ProgressUtils;
//
///**
// * @title 借款债权项目和资金匹配结果内部处理服务
// *
// * @author Percy.Lo
// * @version 1.0
// * @created 2015年4月15日
// */
//@Service
//public class MatchInnerServiceImpl implements IMatchInnerService {
//	@Autowired
//	private ISequenceService sequenceService;
//
//	@Autowired
//	private IFinishProductService finishProductService;
//
//	@Autowired
//	private InvestProdRecordDao investProdRecordDao;
//
//	@Autowired
//	private InvestTransDao investTransDao;
//
//	@Autowired
//	private LoanClaimDao loanClaimDao;
//
//	@Autowired
//	private ProductDao prodDao;
//
//	@Autowired
//	private TransferApplyDao transferApplyDao;
//
//	@Autowired
//	private TransferRecordDao transferRecordDao;
//
//	@Autowired
//	private PlanTransferDao planTransferDao;
//
//	@Autowired
//	private CustClaimDao custClaimDao;
//
//	@Autowired
//	private ReceivePlanDao receivePlanDao;
//
//	@Autowired
//	private CustomerDao customerDao;
//
//	@Autowired
//	private TransProductDao transProductDao;
//
//	@Override
//	public boolean batchInnerSaveMatchedResult(MongoQueueEnum loanQueue, DBObject loanOrClaim, LinkedList<FundResult> matchingInvestList, List<FundResult> tradeDetail, GatheringFoundType gatheringFoundType) throws Exception {
//		if (gatheringFoundType != null) {// 调取资金
//			switch (gatheringFoundType) {
//			case DIRECT:
//			case TRANSFER:
//				saveGatheringFound(loanOrClaim, matchingInvestList, tradeDetail, gatheringFoundType);// 直投产品调取资金
//																										// |
//																										// 自转债权调取资金
//				break;
//			default:
//				throw new Exception("未知的调取资金方式：" + gatheringFoundType);
//			}
//		} else {// 队列匹配
//			switch (loanQueue) {
//			case queueLoanApp:
//			case queueLoanChannel:// app和渠道的项目
//				saveAppOrChannelLoan(loanOrClaim, matchingInvestList, tradeDetail);
//				break;
//			case queueLoanTransfer:// 投资计划债权转让
//				savePlanTransfer(loanOrClaim, matchingInvestList, tradeDetail);
//				break;
//			default:
//				throw new Exception("未知的借款队列：" + loanQueue);
//			}
//		}
//
//		return true;
//	}
//
//	/**
//	 * 更新投资记录
//	 * 
//	 * @param matchingInvestList
//	 *            匹配到的投资记录
//	 * @return
//	 */
//	private boolean updateMatchingInvest(LinkedList<FundResult> matchingInvestList) {
//		InvestProdRecord investProdRecord;
//		for (FundResult e : matchingInvestList) {
//			DBObject fund = e.getFund();
//			String fundId = (String) fund.get(ID);// 投资记录id
//			long fundVersion = Long.valueOf((String) fund.get(VERSION));// 投资，mysql数据记录的版本号
//			BigDecimal fundSurplusAmount = new BigDecimal((String) fund.get(INVEST_SURPLUS_AMOUNT));// 投资剩余金额
//			investProdRecord = new InvestProdRecord(fundVersion, fundId, fundSurplusAmount);
//			investProdRecordDao.updateByPrimaryKeySelectiveByVersion(investProdRecord);// 更新投资记录
//		}
//		return true;
//	}
//
//	/**
//	 * app借款项目和渠道项目的匹配结果保存
//	 * 
//	 * @param loanOrClaim
//	 *            借款项目信息
//	 * @param tradeDetail
//	 *            匹配到的资金
//	 * @throws Exception
//	 *             异常情况(包括数据记录version发生变更)
//	 */
//	private boolean saveAppOrChannelLoan(DBObject loanOrClaim, LinkedList<FundResult> matchingInvestList, List<FundResult> tradeDetail) throws Exception {
//		String loanId = (String) loanOrClaim.get(ID);// 借款项目Id
//		long loanVersion = Long.valueOf((String) loanOrClaim.get(VERSION));// 借款项目version（mysql）
//		/*---更新项目状态，发布状态为满标、借款审批状态为面签准备---*/
//		LoanClaim loanClaim = new LoanClaim(loanVersion, loanId, ReleaseStatus.MATCHING.getCode());
//		loanClaim.setAuditStatus(LoanAuditStatus.VIEW_PREPARE.getCode());
//		loanClaimDao.updateByPrimaryKeySelectiveByVersion(loanClaim);
//		/*---更新投资记录---*/
//		updateMatchingInvest(matchingInvestList);
//		InvestTrans investTrans;
//		/*---新增交易记录---*/
//		for (FundResult e : tradeDetail) {
//			DBObject fund = e.getFund();
//			String fundId = (String) fund.get(ID);// 投资记录id
//			long fundUserId = Long.valueOf((String) fund.get(USER_ID));// 投资人Id
//			BigDecimal matchedAmount = new BigDecimal((String) fund.get(SINGLE_TRADE_AMOUT));// 该笔交易金额
//			String investMethod = InvestMethod.PLAN.getCode();
//			String investRransStatus = DictConstant.INVEST_TRANS_STATUS.INVESTING.getCode();
//			String investNo = sequenceService.getCompleteSequenceBySeqKey("TZJY"); // 投资交易编号
//			investTrans = new InvestTrans(null, investNo, loanId, fundUserId, matchedAmount, investRransStatus, new Date(), investMethod, fundId, matchedAmount, null, null);
//			investTransDao.insertSelective(investTrans);
//		}
//		return true;
//	}
//
//	/**
//	 * 调取资金的匹配结果保存
//	 * 
//	 * @param loanOrClaim
//	 *            借款项目信息
//	 * @param tradeDetail
//	 *            匹配到的资金
//	 * @param gatheringFoundType
//	 *            调取资金的方式，null表示非调取资金
//	 * @throws Exception
//	 *             异常情况(包括数据记录version发生变更)
//	 */
//	private boolean saveGatheringFound(DBObject loanOrClaim, LinkedList<FundResult> matchingInvestList, List<FundResult> tradeDetail, GatheringFoundType gatheringFoundType) throws Exception {
//		String loanId = (String) loanOrClaim.get(ID);// 借款项目
//		long productVersion = Long.valueOf((String) loanOrClaim.get(VERSION));// 产品version，mysql数据记录的版本号
//		String productCode = (String) loanOrClaim.get("_productCode");// 直投产品|自转债权产品编号
//		BigDecimal loanAmount = new BigDecimal((String) loanOrClaim.get(lOAN_AMOUNT));// 调取资金的额度（债权金额）
//		String ratiostr = (String) loanOrClaim.get("_ratio");// （可选，转让比率——转让债权金额比上转让价格）
//		BigDecimal surplusAmount = new BigDecimal((String) loanOrClaim.get("_surplusAmount"));// 剩余可投金额
//		BigDecimal projectAmount = new BigDecimal((String) loanOrClaim.get("_projectAmount"));// 该笔借款额度或渠道存量债权余额或债权转让的额度
//		int investorCount = Integer.parseInt((String) loanOrClaim.get("_investorCount"));// 投资人数
//		String srcCreditNo = (String) loanOrClaim.get("_srcCreditNo");// 出让人债权编号（可选，自转债权调取资金才有该参数）
//		String serialNo = (String) loanOrClaim.get("_serialNo");// 债权转让申请编号（可选，自转债权调取资金才有该参数）
//		String recordNo = (String) loanOrClaim.get("_recordNo");// 债权转让者的投资记录id（可选，自转债权调取资金才有该参数）
//		String creditVersion = (String) loanOrClaim.get("_creditVersion");// 转让债权的版本号，防止同时有还款操作（可选，自转债权调取资金才有该参数）
//		/*---更新产品进度&剩余可投金额---*/
//		BigDecimal[] pu = ProgressUtils.calculate(loanAmount, surplusAmount, projectAmount);
//		BigDecimal progress = pu[0];
//		BigDecimal newSurplusAmount = pu[1];
//		Product product = new Product(productVersion, productCode, investorCount + 1, progress, newSurplusAmount);
//		boolean isFullScale = (progress.compareTo(BigDecimal.valueOf(100L)) == 0);
//		if (isFullScale) {// 满标
//			product.setFullScaleDate(new Date());
//		}
//		prodDao.updateProductByVersion(product);
//
//		/*---更新投资记录---*/
//		updateMatchingInvest(matchingInvestList);
//		/*---新增交易记录---*/
//		InvestTrans investTrans;
//		BigDecimal ratio = (ratiostr == null) ? BigDecimal.ONE : new BigDecimal(ratiostr);// 投资
//		int step = 1, len = tradeDetail.size();
//		BigDecimal totalActualAmount = BigDecimal.ZERO;// 所有交易的债权金额的累计
//		for (FundResult e : tradeDetail) {
//			DBObject fund = e.getFund();
//			String fundId = (String) fund.get(ID);// 投资记录id
//			long fundUserId = Long.valueOf((String) fund.get(USER_ID));// 投资人Id
//			BigDecimal matchedAmount = new BigDecimal((String) fund.get(SINGLE_TRADE_AMOUT));// 该笔交易金额（或投资价格）
//			String investMethod = gatheringFoundType == GatheringFoundType.DIRECT ? InvestMethod.DIRECT.getCode() : InvestMethod.TRANSFER.getCode();
//			String investRransStatus = DictConstant.INVEST_TRANS_STATUS.INVESTING.getCode();
//			BigDecimal actualAmount = matchedAmount;// 单笔交易购买对应的债权金额
//			if (ratio.compareTo(BigDecimal.ONE) != 0) {
//				actualAmount = matchedAmount.multiply(ratio).setScale(CURRENCY_DB_SCALE, RoundingMode.DOWN);
//				if (step == len) {// 尾差处理，把债权金额的比例拆分误差计到最后一笔交易上
//					actualAmount = loanAmount.subtract(totalActualAmount);
//				}
//				totalActualAmount = totalActualAmount.add(actualAmount);
//			}
//			String investNo = sequenceService.getCompleteSequenceBySeqKey("TZJY"); // 投资交易编号
//			investTrans = new InvestTrans(null, investNo, loanId, fundUserId, actualAmount, investRransStatus, new Date(), investMethod, fundId, matchedAmount, srcCreditNo, productCode);
//			investTransDao.insertSelective(investTrans);
//			step++;
//		}
//		if (isFullScale) {// 满标
//			if (gatheringFoundType == GatheringFoundType.DIRECT) {/*---直投产品的调取资金，更新项目发布状态为满标、借款审批状态为面签准备---*/
//				LoanClaim lc = loanClaimDao.selectByPrimaryKey(loanId);
//				LoanClaim updateLoanClaim = new LoanClaim(lc.getVersion(), loanId, ReleaseStatus.FULL_SCALE.getCode());
//				updateLoanClaim.setAuditStatus(LoanAuditStatus.VIEW_PREPARE.getCode());
//				loanClaimDao.updateByPrimaryKeySelectiveByVersion(updateLoanClaim);
//			} else {// 自转债权的调取资金
//					saveSelfTransfer(serialNo, recordNo, creditVersion, productCode);
//			}
//		}
//		return true;
//	}
//
//	
//	/**
//	 * 计划类债权退出时的操作
//	 * @param loanOrClaim 债权信息
//	 * @param tradeDetail 匹配到的资金
//	 */
//	private boolean savePlanTransfer(DBObject loanOrClaim, LinkedList<FundResult> matchingInvestList, List<FundResult> tradeDetail) throws Exception {
//		String loanId = (String) loanOrClaim.get(TR_PROJECT_NO);// 债权转让项目Id
//		String creditNo = (String) loanOrClaim.get(TR_CREDIT_NO);// 转让的债权编号
//		String recordNo = (String) loanOrClaim.get(TR_RECORD_NO);// 转让人的投资记录编号
//		BigDecimal transferAmount = new BigDecimal((String) loanOrClaim.get(lOAN_AMOUNT));// 债权转让本金
//		// 更新接收人的投资记录
//		updateMatchingInvest(matchingInvestList);
//
//		// 生成投资交易记录
//		List<InvestTrans> investTransList = new ArrayList<InvestTrans>();
//		for (FundResult e : tradeDetail) {
//			DBObject fund = e.getFund();
//			String fundId = (String) fund.get(ID);// 投资记录id
//			long fundUserId = Long.valueOf((String) fund.get(USER_ID));// 投资人Id
//			BigDecimal matchedAmount = new BigDecimal((String) fund.get(SINGLE_TRADE_AMOUT));// 该笔交易金额（或投资价格）
//			String investMethod = InvestMethod.TRANSFER.getCode();
//			String investRransStatus = DictConstant.INVEST_TRANS_STATUS.ASSIGNED.getCode();
//			String investNo = sequenceService.getCompleteSequenceBySeqKey("TZJY"); // 投资交易编号
//			InvestTrans investTrans = new InvestTrans(null, investNo, loanId, fundUserId, matchedAmount, investRransStatus, new Date(), investMethod, fundId, matchedAmount, creditNo, null);
//			investTransDao.insertSelective(investTrans);
//			investTransList.add(investTrans);
//		}
//		// 更新转让计划表
//		PlanTransfer planTransfer = planTransferDao.selectByPrimaryKey(recordNo);
//		int creditClaimCount = planTransfer.getCreditClaimCount() - 1;// 计数器减1, 全部转让出去后 更新投资记录
//		PlanTransfer ptf = new PlanTransfer(recordNo);
//		boolean isAllTransfer = creditClaimCount == 0;
//		if (isAllTransfer)// 该投资计划全部转让，则标记已退出
//			ptf.setStatus(PlanAuditStatus.QUITTED.getCode());
//		ptf.setCreditClaimCount(creditClaimCount);
//		ptf.setVersion(planTransfer.getVersion());
//		planTransferDao.updateByPrimaryKeySelectiveByVersion(ptf);
//		return saveTransfer(loanOrClaim, investTransList, transferAmount, true, isAllTransfer);
//	}
//	
//	/**
//	 * 自转债权满标操作
//	 * @param serialNo 债权转让申请编号
//	 * @param recordNo 债权转让者的投资记录id
//	 * @param creditVersion 转让债权的版本号，防止同时有还款操作
//	 * @param transProductCode 债权转让产品的代码
//	 */
//	@Override
//	public boolean saveSelfTransfer(String serialNo, String recordNo, String creditVersion, String transProductCode) throws Exception {
//		TransferApply transferApply = transferApplyDao.selectTransferApplyBySerialNo(serialNo);
//		InvestProdRecord investProdRecord = investProdRecordDao.selectByPrimaryKey(recordNo);
//		TransProduct transProduct = transProductDao.selectByPrimaryKey(transProductCode);
//		// 债权参数
//		DBObject claim = new BasicDBObject();
//		claim.put(ID, serialNo);
//		claim.put(VERSION, transferApply.getVersion());
//		claim.put(USER_ID, transProduct.getSeller().toString());
//		claim.put(TR_PROJECT_NO, transProduct.getProjectNo());
//		claim.put(TR_RECORD_NO, recordNo);
//		claim.put(TR_CREDIT_NO, transProduct.getCreditNo());
//		claim.put(TR_CREDIT_VERSION, creditVersion);
//		claim.put(PRODUCT_CODE, investProdRecord.getProdCode());
//		claim.put(PRODUCT_NAME, investProdRecord.getProdName());
//		claim.put(lOAN_AMOUNT, transProduct.getAmount());
//
//		// 投资记录参数 & 更新交易记录
//		List<InvestTrans> investTransList = investTransDao.selectListBySrcCreditNo(transProduct.getCreditNo());
//		for (InvestTrans trans : investTransList) {
//			String investRransStatus = DictConstant.INVEST_TRANS_STATUS.ASSIGNED.getCode();
//			trans.setStatus(investRransStatus);//已配资
//			investTransDao.updateByPrimaryKeySelective(trans);
//		}
//		return saveTransfer(claim, investTransList, transProduct.getPrice(), false, true);
//	}
//
//	/**
//	 * 债权转让公共部分（更新转让申请、更新用户债权信息、更新回款计划、生成转让记录、转让服务费、划转、生成新债权、回款计划、更新转让人的投资记录、解冻剩余投资金额、计算平台补贴）
//	 * @param loanOrClaim 债权信息
//	 * @param investTransList 投资信息
//	 * @param transferPrice 转让对价
//	 * @param isPlan 是否是计划类转让
//	 * @param isAllTransfer 是否已全部转让
//	 */
//	private boolean saveTransfer(DBObject loanOrClaim, List<InvestTrans> investTransList, BigDecimal transferPrice, boolean isPlan, boolean isAllTransfer) throws Exception {
//		String serialNo = (String) loanOrClaim.get(ID);// 债权转让申请编号
//		long ver = Long.valueOf((String) loanOrClaim.get(VERSION));// 债权转让申请版本号
//		long creditUserId = Long.valueOf((String) loanOrClaim.get(USER_ID));// 债权转让人Id
//		String loanId = (String) loanOrClaim.get(TR_PROJECT_NO);// 债权转让项目Id
//		String recordNo = (String) loanOrClaim.get(TR_RECORD_NO);// 转让人的投资记录编号
//		String creditNo = (String) loanOrClaim.get(TR_CREDIT_NO);// 转让的债权编号
//		Long creditVersion = Long.valueOf((String) loanOrClaim.get(TR_CREDIT_VERSION));// 转让的用户债权版本号
//		String productCode = (String) loanOrClaim.get(PRODUCT_CODE);// 转让人的投资产品代码
//		String productName = (String) loanOrClaim.get(PRODUCT_NAME);// 转让人的投资产品名称
//		String productType = isPlan ? ProductIdType.CPJH.getCode() : ProductIdType.CPZT.getCode();// 产品类型
//		BigDecimal transferAmount = new BigDecimal((String) loanOrClaim.get(lOAN_AMOUNT));// 债权转让本金
//		// 更新债权转让申请记录
//		TransferApply transferApply = new TransferApply(serialNo, BigDecimal.ZERO, TranferStatus.MATCHED.getCode(), ver);
//		transferApplyDao.updateByPrimaryKeySelectiveByVersion(transferApply);
//
//		// 更新转让人用户债权信息
//		CustClaim custClaim = custClaimDao.selectCustClaimByCreditNo(creditNo);
//		if (creditVersion != custClaim.getVersion())// 发生还款的情况会导致这里失败
//			throw new StaleObjectStateException("用户债权信息已发生变化(如还款): creditNo=" + creditNo);
//		CustClaim newCustClaim = new CustClaim(creditNo, BigDecimal.ZERO, CreditTransStatus.TRANSFERRED.getCode(), BigDecimal.ZERO, BigDecimal.ZERO, custClaim.getVersion());
//		custClaimDao.updateByPrimaryKeySelectiveByVersion(newCustClaim);
//
//		// 更新回款计划，逻辑删除所有该债权的计划
//		receivePlanDao.deleteByClaimNo(creditNo);
//
//		// 生成新债权id & 生成转让记录
//		for (InvestTrans trans : investTransList) {
//			//生成新债权编号
//			String newCreditNo = sequenceService.getCompleteSequenceBySeqKey("ZQBH");// 接收人的债权编号
//			trans.setNewCreditNo(newCreditNo);//子流程生成新债权用
//			String sellerName = getLoginName(creditUserId);
//			String buyerName = getLoginName(trans.getCustId());
//			// add TransferRecord
//			TransferRecord transferRecord = new TransferRecord(null, loanId, trans.getCustId(), creditUserId, trans.getInvestPrice(), trans.getInvestAmount(), new Date(), productType, ProductIdType.CPJH.getCode(), creditNo, sellerName, buyerName, newCreditNo, trans.getProductCode(), null, productCode, productName);
//			transferRecordDao.insertSelective(transferRecord);
//		}
//		// 转让服务费
//		BigDecimal transferServiceCharge = BigDecimal.ZERO;
//		if (!isPlan) {// 自转债权才有转让服务费
//			BigDecimal transferRate = transProductDao.selectByPrimaryKey(productCode).getTransferRate();
//			transferServiceCharge = CalculateBusiUtils.TransferServiceCharge(transferAmount, transferRate);
//		}
//		// 划转、生成新债权、回款计划
//		finishProductService.saveCommon(loanId, creditUserId, transferPrice, investTransList, "P2P", transferServiceCharge);
//
//		// 更新转让人的投资记录
//		if (isAllTransfer) {// 该投资计划全部转让，则标记已转让
//			InvestProdRecord investProdRecord = investProdRecordDao.selectByPrimaryKey(recordNo);
//			InvestProdRecord newInvestProdRecord = new InvestProdRecord(investProdRecord.getVersion(), recordNo, BigDecimal.ZERO);
//			newInvestProdRecord.setInvestStatus(INVEST_RECORD_STATUS.TRANSFERRED.getCode());
//			investProdRecordDao.updateByPrimaryKeySelectiveByVersion(newInvestProdRecord);// 更新投资记录
//
//			// TODO 易宝 解冻剩余投资金额  investProdRecord.getRemainAmount();//解冻剩余金额
//
//			// 计划类转让需要计算补贴（本金、约定收益、约定奖励）
//			if (isPlan) {
//				Product product = prodDao.getProductByProdCode(productCode);
//				BigDecimal addYield = product.getAddYield();// 附加收益
//				BigDecimal investAmount = investProdRecord.getInvestAmount();// 投资金额
//				BigDecimal remainAmount = investProdRecord.getRemainAmount();// 实际收益+本金(债权转让后的所有金额)
//				String termType = investProdRecord.getTermType();// 投资期限周期
//				BigDecimal yearRate = investProdRecord.getYearRate();// 预期年化收益率
//				int investTerm = investProdRecord.getInvestTerm();// 投资期限
//				BigDecimal subsidy = CalculateBusiUtils.platformSubsidies(investAmount, remainAmount, termType, investTerm, yearRate, addYield);// 平台补贴
//				// TODO 易宝 平台补贴subsidy划转到计划类转让者
//			}
//		}
//		return true;
//	}
//
//	
//	// customer name Cache
//	private final Map<Long, String> customerCache=new ConcurrentHashMap<Long, String>();
//	/**
//	 * 获取客户的登录名（cache）
//	 * @param custId 客户Id
//	 * @return 登录名
//	 */
//	private String getLoginName(long custId) {
//		String name = customerCache.get(custId);
//		if (name == null) {
//			Customer customer = customerDao.selectByCustId(custId);
//			name=customer.getLoginName();
//			customerCache.put(custId, name);
//		}
//		return name;
//	}
//}
